<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="/static/pear/component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form">
    <div class="mainBox  layui-card-body" style="padding: 0 0;">
        <div class="main-container">
            <div id="one"></div>
        </div>
    </div>


    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
        </div>
    </div>
</form>
{include file="_Fragment/javascript" /}
<script>
    layui.use(['form', 'jquery', 'element', 'transfer'], function() {
        let form = layui.form;
        let $ = layui.jquery;
        let transfer = layui.transfer;
        let field = '{$field}';
        let courseid = {$courseid};
        let rule_id = {$rule_id};

        $.ajax({
            url: "/Course/getshowField",
            data:{type:field, courseid:courseid, rule_id:rule_id},
            dataType: 'json',
            type: 'post',
            success: function(res) {

                //显示搜索框
                transfer.render({
                    elem: '#one'
                    ,data: res.data.fields
                    ,width: 300
                    ,height: 400
                    ,text: {
                        none: '无数据' //没有数据时的文案
                        ,searchNone: '无匹配数据' //搜索无匹配数据时的文案
                    }
                    ,title: ['全选', '已选']
                    ,showSearch: true
                    ,value: res.data.s
                    ,id: 'one'
                })
            }
        })


        form.on('submit(user-save)', function() {
            var data = transfer.getData('one');
            var type = '{$field}';

            if (data == '') {
                var value = '';
            } else {
                var value = [];
                for ( var i = 0; i < data.length; i++){
                    value.push(data[i].value);
                    value.join(',')
                }
            }

            layer.confirm('确定保存吗?', {icon: 3, title:'提示'}, function(){
                parent.$('#'+type).val(value);
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            });
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>